package org.net.cms.controller.admin.leave;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.net.cms.config.Result;
import org.net.cms.service.leave.StudentLeaveService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/leave")
@Tag(name = "管理后台 - 学生请假")
public class StudentLeaveController {

    @Resource
    private StudentLeaveService studentLeaveService;

    @GetMapping("/list")
    @Operation(summary = "获取申请列表")
    @Parameter(name = "type", description = "0待审核，1已审核", required = true)
    public Result getAllLeaves(int type) {
        return Result.success(studentLeaveService.findListByType(type));
    }

    @GetMapping("/get")
    @Operation(summary = "获取申请详情")
    @Parameter(name = "id", description = "请假id", required = true)
    public Result get(int id) {
        return Result.success(studentLeaveService.findById(id));
    }

    @PostMapping("/delete")
    @Operation(summary = "删除申请列表")
    @Parameter(name = "id", description = "申请id", required = true)
    public Result delete(int id) {
        studentLeaveService.delete(id);
        return Result.success();
    }

    @PostMapping("/update")
    @Operation(summary = "修改审核状态")
    @Parameter(name = "id", description = "申请id", required = true)
    @Parameter(name = "status", description = "审核状态1同意，0待审核")
    public Result updateStatus(@RequestParam int id, @RequestParam int status) {
        studentLeaveService.updateStatus(id, status);
        return Result.success("修改成功！");
    }


}
